package com.slimbloody.score.rule;

import com.slimbloody.dto.Score;
import com.slimbloody.dto.WholesaleDrug;
import com.slimbloody.score.Param.Cal1Param;
import com.slimbloody.score.Param.Match1Param;
import com.slimbloody.score.Param.RequestParam;
import com.slimbloody.score.context.cal.Cal1Context;
import com.slimbloody.score.context.match.Match1Context;
import com.slimbloody.score.interfaces.Rule;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Component
public class Rule1 implements Rule<Match1Param, Match1Context, Cal1Param, Cal1Context> {

  @Override
  public Match1Context fetchMatchContext(Match1Param match1Param) {
    if (Objects.isNull(match1Param)) {
      return null;
    }
    return new Match1Context("123");
  }

  @Override
  public boolean match(Match1Context match1Context) {
    return match1Context.getWd1().equals("123");
  }

  @Override
  public Cal1Context fetchCalContext(Cal1Param cal1Param) {
    return null;
  }

  @Override
  public Map<Integer, Score> cal(List<WholesaleDrug> list, Cal1Context context) {
    return new HashMap<>();
  }

  public Map<Integer, Score> execute(RequestParam param, List<WholesaleDrug> list) {
    // param => Match1Param match1Param
    Match1Param match1Param = new Match1Param("123");
    Match1Context match1Context = fetchMatchContext(match1Param);

    if (!match(match1Context)) {
      return null;
    }

    // param => Cal1Param cal1Param
    Cal1Param cal1Param = new Cal1Param();
    Cal1Context cal1Context = fetchCalContext(cal1Param);

    return cal(list, cal1Context);
  }
}
